package com.bajie.bjlisten.sevice;

import com.bajie.bjlisten.entity.BJMenuChild;
import com.bajie.bjlisten.mapper.BjMenuMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 菜单权限
 */
@Service
public class MenuPermissionService {
    private static final Logger log = LoggerFactory.getLogger("adminLogger");

    @Autowired
    private BjMenuMapper bjMenuMapper;


    /**
     * 保存菜单
     *
     * @param bjMenu
     */
    public void save(BJMenuChild bjMenu) {
        bjMenuMapper.saveMenu(bjMenu);

        log.debug("新增菜单{}", bjMenu.getMenu_name());
    }

    /**
     * 更新菜单
     *
     * @param bjMenu
     */
    public void update(BJMenuChild bjMenu) {
        bjMenuMapper.updateMenu(bjMenu);
    }

    /**
     * 删除菜单
     *
     * @param menu_id
     */

    @Transactional
    public void delete(String menu_id) {
        bjMenuMapper.deleteRolePermission(menu_id);
        bjMenuMapper.deleteById(menu_id);
        bjMenuMapper.deleteByParentId(menu_id);

        log.debug("删除菜单id:{}", menu_id);
    }
}
